﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IntellectShop.Common
{
	public partial class OrderItem : IEquatable<OrderItem>
	{
		public int OrderItemID { get; set; }

		public int OrderID { get; set; }

		public int CommodityID { get; set; }

		private Common.Commodity _commodity = null;
		public Common.Commodity Commodity
		{
			get
			{
				if (this._commodity == null && this.CommodityID != 0)
				{
					this._commodity = Common.Commodity.RetrieveByID(this.CommodityID);
				}

				return this._commodity;
			}

			private set
			{
				this._commodity = value;
			}
		}

		public int Quantity { get; set; }

		public Common.Money UnitPrice { get; set; }

		[DisplayNameLocalized("CreatedBy")]
		public string CreatedBy { get; set; }

		[DisplayNameLocalized("Created")]
		public DateTime? Created { get; set; }

		#region IEquatable<OrderItem> Members

		public bool Equals(OrderItem other)
		{
			return (this.OrderItemID == other.OrderItemID &&
				this.OrderID == other.OrderID &&
				this.CommodityID == other.CommodityID &&
				this.Quantity == other.Quantity &&
				this.Quantity == other.Quantity);
		}

		public override bool Equals(Object obj)
		{
			if (obj == null) return base.Equals(obj);

			if (!(obj is OrderItem))
				throw new InvalidCastException("The 'obj' argument is not a OrderItem object.");
			else
				return Equals(obj as OrderItem);
		}

		public override int GetHashCode()
		{
			return this.OrderItemID;
		}

		public static bool operator ==(OrderItem obj1, OrderItem obj2)
		{
			return obj1.Equals(obj2);
		}

		public static bool operator !=(OrderItem obj1, OrderItem obj2)
		{
			return (!obj1.Equals(obj2));
		}

		#endregion
	}
}
